var app = getApp();
var fr5ssidset='';
var fr5pwdset='';
Page({
  data:{
    fr5ssid:'',
    fr5pwd:'',
    ssidname:'',
    ssidpwd:'',
    id:'',
    wirelessid:''
  },
  onLoad:function(options){
    console.log(options.title);
    console.log(options.id);
    this.setData({
      id:options.id
    })
    // 页面初始化 options为页面跳转所带来的参数
    // this.setData({
    //   ssidname:options.title
    // })
    var that =this;
    wx.request({
            url: 'https://cd.tunnel.litelink.me/v1/smallapp/querySSIDInfo',
            method:'GET',
            data:{
                ssidname : options.title,
                sn:app.globalData.SN,
                wirelessid:options.wirelessid
            },
            header:{
                "Content-Type":"application/json"
            },
            success: function(res) {
              console.log(res.data);
              
                that.setData({
                  wirelessid:res.data.id,
                  ssidpwd:res.data.ssidpwd,
                  ssidname:res.data.ssidname
                })
            }
    });

    
  
    
  },
  onReady:function(){
    // 页面渲染完成
    
  },
  onShow:function(){
    // 页面显示
    this.setData({
      fr5ssid:app.globalData.fr5ssid,
      fr5pwd:app.globalData.fr5pwd,
    })
    
  },
  onHide:function(){
    // 页面隐藏
    
  },
  onUnload:function(){
    // 页面关闭
    
  },
  back:function(){
      console.log("back");
      wx.navigateBack({
          delta:1
      });
  },
  confirm:function(){

     wx.request({
            url: 'https://cd.tunnel.litelink.me/v1/smallapp/modifyWifi5G',
            method:'get',
            data:{
                fr5ssidset : fr5ssidset,
                fr5pwdset : fr5pwdset,
                deviceid: app.globalData.deviceid,
                id:this.data.id,
                sn:app.globalData.SN,
                wirelessid:this.data.wirelessid
            },
            header:{
                "Content-Type":"application/json"
            },
            success: function(res) {
              console.log(res)
                if(res.data == "ok"){
                  wx.showToast({
                    title: '已修改',
                    icon: 'success',
                    duration: 2000
                  }),       
                  wx.navigateBack({
                      delta:2
                  });    
                  app.globalData.fr5ssid=fr5ssidset;
                  app.globalData.fr5pwd=fr5pwdset;          
                }else{
                  wx.showToast({
                    title: '修改失败',
                    icon: 'success',
                    duration: 2000
                  })
                }
            }
    });
    wx.showToast({
      title: '正在修改',
      icon: 'loading',
      duration: 10000
    })
    
  },
  delete:function(){
     wx.request({
            url: 'https://cd.tunnel.litelink.me/v1/smallapp/deleteSSID',
            method:'get',
            data:{
                fr5ssidset : fr5ssidset,
                fr5pwdset : fr5pwdset,
                deviceid: app.globalData.deviceid,
                id:this.data.id,
                sn:app.globalData.SN,
                wirelessid:this.data.wirelessid
            },
            header:{
                "Content-Type":"application/json"
            },
            success: function(res) {
              console.log(res)
                if(res.data == "ok"){
                  wx.showToast({
                    title: '已删除',
                    icon: 'success',
                    duration: 2000
                  }),       
                  wx.navigateBack({
                      delta:2
                  });    
                  app.globalData.fr5ssid=fr5ssidset;
                  app.globalData.fr5pwd=fr5pwdset;          
                }else{
                  wx.showToast({
                    title: '删除失败',
                    icon: 'info',
                    duration: 2000
                  })
                }
            }
    });
    wx.showToast({
      title: '正在删除',
      icon: 'loading',
      duration: 10000
    })
    
  },
  fr5ssidset:function(e){ 
      fr5ssidset=e.detail.value;  
  },
  fr5pwdset:function(e){
      fr5pwdset=e.detail.value;   
  }
})